// eslint-disable-next-line
/* eslint-disable */
import Vue from 'vue'
import App from './App.vue'
import router from './router.js'
import store from './store.js'
import rem from "../common/js/rem.js"
import holderjs from "holderjs"
import fastclick from "fastclick"
import VueQuillEditor from 'vue-quill-editor'
import VConsole from 'vconsole/dist/vconsole.min.js'
import api from '../src/api/api.js'
import qs from 'qs'
import axios from 'axios'
// 全局引入axios
// import axios from "axios"
import "mint-ui/lib/style.css"
import "../public/sass/mint-user.scss"
let vConsole = new VConsole() // 初始化
window.api = api

// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor, /* { default global options } */)
// 全局引入iconfont图标
import "../public/iconfont/iconfont.css"
import "../public/css/vue-edit.css"

// 图片懒加载
import VueLazyload from 'vue-lazyload'
// 全局拦截处理
// 处理后台获取不到前台传递数据
// 拦截处理
axios.interceptors.request.use((req) => {
    if (req.method === 'post') {
      // 转换成JSON格式
      req.data = qs.stringify(req.data);
    }
    return req;
}, (error) => Promise.reject(error));

// 使用全局使用axios
// window.axios = axios
// Vue.prototype.$axios = axios
// axios.defaults.baseURL = "http://localhost:8080"
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: require('../public/images/error.jpg'),   //请求失败后显示的图片
  loading: require('../public/images/loading.gif'),   //加载的loading过渡图片
  attempt: 1     // 加载图片数量
})

// fastclick.attach(document.body);

Vue.config.productionTip = false
// 动态显示title
// 在进入下一个路由的时候，就获取到下一个页面的title显示出来
// 需要注册一个全局守卫
router.beforeEach((to, from, next)=>{
  
  if(to.path=='/'){
    //如果即将进入登录页面就是直接放心进入
    next()
  }else{
    if(to.meta.requiresAuth && !localStorage.getItem('token')){
      // 验证token是否存在
      // to.meta.requiresAuth 是否为真
      next({
        path: '/',
      })
    }else{
      if(to.meta.title){
        document.title = to.meta.title
      }
      next();
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
